import { ref } from 'vue'

export interface ProjectConfigurationInfo {
  id: number
  key: string
  value: string
  comment: string
}

export function useGetProjectConfigurationInfo(baseUrl: string, params: { id: number; configurationId: number }) {
  const info = ref<ProjectConfigurationInfo | null>(null)
  const loading = ref(false)
  const error = ref<string | null>(null)

  async function fetchInfo() {
    loading.value = true
    error.value = null
    try {
      const url = `${baseUrl}/api/project/configuration-info?id=${params.id}&configurationId=${params.configurationId}`
      const res = await fetch(url)
      if (!res.ok) throw new Error('网络错误')
      info.value = await res.json()
    } catch (e: any) {
      error.value = e.message || '未知错误'
    } finally {
      loading.value = false
    }
  }

  return { info, loading, error, fetchInfo }
}
